package com.htht.smartschool.action.schoolbus;

import java.util.List;

import com.google.gson.Gson;
import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.schoolbus.TBus;
import com.htht.smartschool.model.schoolbus.TBuswarn;
import com.htht.smartschool.model.schoolbus.TDriver;
import com.htht.smartschool.model.schoolbus.TLine;
import com.htht.smartschool.service.schoolbus.SchoolBusService;
import com.htht.smartschool.util.system.GsonUtils;

public class ShoolBusAction extends BaseAction{

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		 
		
		boolean flag = false;
		SchoolBusService shoolBus = new SchoolBusService();
		TLine tLine = (TLine) GsonUtils.getInstance().fromJson(pd.getData(), TLine.class);
		TBus tbus = (TBus) GsonUtils.getInstance().fromJson(pd.getData(), TBus.class);
		TDriver tdriver = (TDriver) GsonUtils.getInstance().fromJson(pd.getData(), TDriver.class);
		TBuswarn tbuswarn = (TBuswarn) GsonUtils.getInstance().fromJson(pd.getData(), TBuswarn.class);
		if(pd.getCmd().equalsIgnoreCase("getschoolbuslineinfo")){
			List<TLine> list = shoolBus.getSchoolBusLineInfo(tLine);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询校车路线信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getschoolbusinfo")){
			List<TBus> list = shoolBus.getSchoolBusInfo(tbus);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询校车信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addschoolbus")){
			TBus bus = shoolBus.addSchoolBus(tbus);
			if(bus != null){
				flag = true;
				obj.setData(bus);
			}else{
				obj.setData("添加校车失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateschoolbus")){
			TBus bus = shoolBus.updateSchoolBus(tbus);
			if(bus != null){
				flag = true;
				obj.setData(bus);
			}else{
				obj.setData("更新校车信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteschoolbus")){
			Boolean result = shoolBus.deleteSchoolBus(tbus);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除校车信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getschoolbusdriverinfo")){
			List<TDriver> list = shoolBus.getSchoolBusDriverInfo(tdriver);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询校车司机信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addschoolbusdriver")){
			TDriver driver = shoolBus.addSchoolBusDriver(tdriver);
			if(driver != null){
				flag = true;
				obj.setData(driver);
			}else{
				obj.setData("添加校车司机失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateschoolbusdriver")){
			TDriver driver = shoolBus.updateSchoolBusDriver(tdriver);
			if(driver != null){
				flag = true;
				obj.setData(driver);
			}else{
				obj.setData("更新校车司机失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteschoolbusdriver")){
			Boolean result = shoolBus.deleteSchoolBusDriver(tdriver);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除校车司机失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getschoolbuswarninfo")){
			List<TBuswarn> list = shoolBus.getSchoolBuswarnInfo(tbuswarn);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查询校车预警信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addschoolbuswarn")){
			TBuswarn buswarn = shoolBus.addSchoolBuswarn(tbuswarn);
			if(buswarn != null){
				flag = true;
				obj.setData(buswarn);
			}else{
				obj.setData("添加校车预警信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateschoolbuswarn")){
			TBuswarn buswarn = shoolBus.updateSchoolBuswarn(tbuswarn);
			if(buswarn != null){
				flag = true;
				obj.setData(buswarn);
			}else{
				obj.setData("更新校车预警信息失败");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteschoolbuswarn")){
			Boolean result = shoolBus.deleteSchoolBuswarn(tbuswarn);
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("删除校车预警信息失败");
			}
		}else{
			obj.setData("cmd is wrong");
		}
		
		return flag;
	}

}
